package thread;

public class DaemonThreadDemo {
    public static void main(String[] args) {
        Thread main = Thread.currentThread();

        Thread rose = new Thread(() -> {
            if(main.isAlive()==false){
                System.out.println("main已死");
            }
            for (int i = 0; i < 5; i++) {
                System.out.println("rose:let me go ");

                try {
                    Thread.sleep(1000);

                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            System.out.println("rose:啊啊啊啊啊啊啊啊啊啊啊");
            System.out.println("扑通");
        });

        Thread jc = new Thread(()->{
            while (true) {
                if(rose.isAlive()==false){
                    System.out.println("rose已死");
                    break;
                }
            }
        });

        Thread jack = new Thread(() -> {

            if(main.isAlive()==false){
                System.out.println("主线程main已死");
            }

            while(true){
                System.out.println("jack:you jump i jump");

                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });

        jc.start();
        rose.start();
        jack.setDaemon(true);
        jack.start();
    }
}
